package com.example.hospital.mapper;

import com.example.hospital.pojo.Department;
import lombok.Data;
import org.apache.ibatis.annotations.*;

import java.util.List;
/*部门mapper接口*/
@Mapper
public interface DepartmentMapper {

    @Select("SELECT * FROM department WHERE id = #{id}")
    Department findById(Integer id);

    @Select("SELECT * FROM department WHERE name = #{name}")
    Department findByName(Department department);

    @Select("SELECT * FROM department")
    List<Department> findAll();

    @Insert("INSERT INTO department(name, created_at, updated_at) VALUES(#{name}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertDepartment(Department department);

    @Update("UPDATE department SET name=#{name}, updated_at=NOW() WHERE id=#{id}")
    void updateDepartment(Department department);

    @Delete("DELETE FROM department WHERE id=#{id}")
    void deleteDepartment(Integer id);
}
